package com.lablzh.gdxy.repository.design;

import com.lablzh.gdxy.entity.design.StudentDesign;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.List;

public interface StudentDesignRepositoty extends JpaRepository<StudentDesign,Integer> {
    @Transactional
    void deleteByDesignIDAndStudentUsername(Integer designID, String studentUsername);

    List<StudentDesign> findAllByStudentUsername(String username);

    List<StudentDesign> findAllByDesignID(Integer id);

    List<StudentDesign> findAllByDesignIDAndTransSummit(Integer id, String summit);

    List<StudentDesign> findAllByDesignIDAndReportSummit(Integer id,String summit);

    List<StudentDesign> findAllByDesignIDAndTransReview(Integer id, String review);

    List<StudentDesign> findAllByDesignIDAndReportReview(Integer id, String review);

    List<StudentDesign> findAllByDesignIDAndPaperSummit(Integer id, String summit);

    List<StudentDesign> findAllByDesignIDAndPaperReview(Integer id, String review);

    List<StudentDesign> findAllByStudentName(String studentName);

    List<StudentDesign> findAllByCollege(String college);

    List<StudentDesign> findAllByCollegeAndMajor(String college, String major);


    @Modifying
    @Transactional
    @Query("update StudentDesign set transScore=?3,transLevel=?4,transNote=?5,transReview=?6 where designID=?1 and studentUsername=?2")
    void updateTransScoreAndTransLevelAndTransNoteAndTransReviewByDesignIDAndStudentUsername(Integer id, String studentUsername, Integer score, String level, String note,String transReview);
    @Modifying
    @Transactional
    @Query("update StudentDesign set paperScore=?3,paperLevel=?4,paperNote=?5,paperReview=?6 where designID=?1 and studentUsername=?2")
    void updatePaperScoreAndPaperLevelAndPaperNoteAndPaperReviewByDesignIDAndStudentUsername(Integer id, String studentUsername, Integer score, String level, String note,String paperReview);
    List<StudentDesign> findAllByCollegeAndMajorAndClasses(String college, String major, String classes);

    @Modifying
    @Transactional
    @Query("update StudentDesign set reportScore=?3,reportLevel=?4,reportNote=?5,reportReview=?6 where designID=?1 and studentUsername=?2")
    void updateReportScoreAndReportLevelAndReportNoteAndReportReviewByDesignIDAndStudentUsername(Integer id, String studentUsername, Integer score, String level, String note, String reportReview);


    List<StudentDesign> findAllByCollegeAndMajorAndGrade(String college, String major, String grade);


    List<StudentDesign> findAllByCollegeAndDepartmentAndGrade(String college, String department, String grade);

    @Transactional
    void deleteAllByDesignID(Integer id);

    List<StudentDesign> findAllByCollegeAndGrade(String college, String grade);

    @Modifying
    @Transactional
    @Query("update  StudentDesign set reportSummit=?3,reportReview=?4 where designID=?1 and studentUsername=?2 ")
    void updateReportSummitAndReportReviewByDesignIDAndStudentUsername(Integer id, String username,String summit, String review);
    @Modifying
    @Transactional
    @Query("update  StudentDesign set transSummit=?3,transReview=?4 where designID=?1 and studentUsername=?2 ")
    void updateTransSummitAndTransReviewByDesignIDAndStudentUsername(Integer id, String username, String summit,String review);


    @Modifying
    @Transactional
    @Query("update  StudentDesign set paperSummit=?3, paperReview=?4 where designID=?1 and studentUsername=?2 ")
    void updatePaperSummitAndPaperReviewByDesignIDAndStudentUsername(Integer id, String username,String summit, String review);

    @Modifying
    @Transactional
    @Query("update  StudentDesign set reportFilename=?3,reportSummitTime=?4 where designID=?1 and studentUsername=?2 ")
    void updateReportFilenameAndReportSummitTimeByDesignIDAndStudentUsername(Integer id, String username, String filename,LocalDate summitTime);

    @Modifying
    @Transactional
    @Query("update  StudentDesign set transFilename=?3,transSummitTime=?4 where designID=?1 and studentUsername=?2 ")
    void updateTransFilenameAndTransSummitTimeByDesignIDAndStudentUsername(Integer id, String username, String filename,LocalDate summitTime);

    @Modifying
    @Transactional
    @Query("update  StudentDesign set paperFilename=?3,paperSummitTime=?4 where designID=?1 and studentUsername=?2 ")
    void updatePaperFilenameAndPaperSummitTimeByDesignIDAndStudentUsername(Integer id, String username, String filename,LocalDate summitTime);

    StudentDesign findByDesignIDAndStudentUsername(Integer id, String username);

    List<StudentDesign> findAllByStudentNameAndGrade(String studentName, String grade);

    List<StudentDesign> findAllByCollegeAndMajorAndClassesAndGrade(String college, String major, String classes, String grade);

}
